<!doctype html>
<html>
<head ul_clear=5_6pVl >
    <meta charset="utf-8">
    <title>思途CMS{$coreVersion}</title>
    {template 'stourtravel/public/public_min_js'}
    {php echo Common::getCss('base_new.css'); }
    {php echo Common::getScript("uploadify/jquery.uploadify.min.js"); }
    {php echo Common::getCss('uploadify.css','js/uploadify/'); }
    <style>
        .up-img-area{
            width: 60px;
            height: 60px;
        }
    </style>
</head>
<body style=" overflow: hidden">
<div class="s-main">
    <ul class="info-item-block">
        <li>
            <span class="f-l item-text w80 text-r">导航名称：</span>
            <div class="fl mt-3 ml-10 w400">
                <input type="text" name="nav_name" id="nav_name" placeholder="请设置导航名称" class="input-text w200 ml-10" value="{$info['m_title']}">
            </div>
        </li>
        <li>
            <span class="f-l item-text w80 text-r">导航图片{Common::get_help_icon('mobile_dialog_ico_m_ico',true)}：</span>
            <div  class="fl mt-3 ml-10 w400">
                <div id="file_upload" class="btn-file mt-4 hide">
                    <div id="file_upload-button" class="uploadify-button " style="text-indent: -9999px; height: 25px; line-height: 25px; width: 80px; cursor: pointer">
                        <span class="uploadify-button-text">上传图片</span>
                    </div>
                </div>
                <a class="btn btn-primary radius size-S mt-3 ml-10" id="upload_btn" href="javascript:;">上传图片</a>
                <a class="btn btn-grey-outline size-S radius mt-3 ml-10" id="restore_default" href="javascript:;">恢复默认</a>
                {if !empty($info['m_ico'])}
                <div class="pt-10 pb-10 ml-80" id="img"><img id="litimg" class="up-img-area" src="{$info['m_ico']}" /></div>
                {else}
                <div class="pt-10 pb-10 ml-80" id="img"><img id="litimg" class="up-img-area" src="{php echo Common::get_menu_no_ico();}" /></div>
                {/if}
            </div>
        </li>
        <li class="hide">
            <span class="f-l item-text w80 text-r">所属模块：</span>
            <div class="fl select-box w200 mt-3 ml-10">
                <select name="nav_mode" class="select">
                    <option value="">请选择所属模块</option>
                    {loop $xcx_page $k}
                    <option value="{$k['subname']}" {if $info['m_mode']==$k['subname']}selected="selected"{/if} >{$k['title']}</option>
                    {/loop}
                </select>
            </div>
        </li>
        <li class="hide">
            <span class="f-l item-text w80 text-r">选择页面：</span>
            <div class="fl select-box w400 mt-3 ml-10">
                <select name="nav_path" class="select">
                    <option value="">选择页面</option>
                    {loop $weblist $k}
                    <option value="{$k['webid']}">{$k['webname']}</option>
                    {/loop}
                </select>
            </div>
        </li>
        <li class="hide">
            <span class="f-l item-text w80 text-r">页面描述：</span>
            <div class="fl mt-3 ml-10 w400">
                <span class="item-text ml-10" id="page_dis">无</span>
            </div>
        </li>
        <li class="hide">
            <span class="f-l item-text w80 text-r">参数填写{Common::get_help_icon('cfg_xcx_nav_params',true)}：</span>
            <div class="fl mt-3 ml-10 w500">
                <input type="text" name="nav_param" id="nav_param" disabled placeholder="不可设置参数" class="input-text w400 ml-10" value="{$info['m_params']}">
            </div>
        </li>

    </ul>
    <div class="clearfix text-c">
        <a href="javascript:;" class="btn btn-default radius c-999 mr-10 refuse" id="refuse-btn">取消</a>
        <a href="javascript:;" class="btn btn-primary radius" id="confirm-btn">确定</a>
    </div>
</div>
<script type="text/javascript">
    $(function(){

        var xcx_page = {json_encode($xcx_page)};
        var info = {json_encode($info)};

        // 初始化页面选择
        start_init();
        function start_init() {
            if(info)
            {
                change_page(info.m_mode);
                // 设置页面选择
                $("select[name='nav_path']").val(info.m_url);
                // 切换页面选择后操作
                change_path(info.m_url,"select[name='nav_path']");
            }
        }

        // 模块选择切换
        $("select[name='nav_mode']").on("change",function () {
            var subname = $(this).val();
            // 模块切换后设置页面
            change_page(subname);
        });

        // 模块切换后设置页面
        function change_page(subname) {
            var html = '<option value="" selected="selected">选择页面</option>';
            $.each(xcx_page,function (index,item) {
                if(subname === item.subname)
                {
                    var page = item.page;
                    $.each(page,function (index1,item1) {
                        html += '<option value="'+item1.path+'" data-dis="'+item1.dis+'" data-params="'+item1.params+'" selected="selected">'+item1.title+'</option>';
                    });
                }
            });
            // 更新页面选择
            $("select[name='nav_path']").html(html);
            // 页面描述
            $("#page_dis").text("无");
            //参数设置
            var nav_param = $("#nav_param");
            nav_param.attr("placeholder","不可设置参数");
            nav_param.attr('disabled',true);
        }

        // 页面选择
        $("select[name='nav_path']").on("change",function () {
            var path = $(this).val();
            change_path(path,this);
            // 手动切换需要清空参数填写
            $("#nav_param").val("");
        });
        // 页面选择
        function change_path(path,obj) {
            var dis = "无";
            var params_dis = "不可设置参数";
            var is_params = false;
            if(path)
            {
                dis = $(obj).find("option:selected").attr("data-dis");
                var params = $(obj).find("option:selected").attr("data-params");
                if(params)
                {
                    params_dis = "可设置参数："+params;
                    is_params = true;
                }
            }
            var nav_param = $("#nav_param");
            nav_param.attr("placeholder",params_dis);
            nav_param.attr('disabled',true);
            if(is_params)
            { // 可设置参数
                nav_param.attr('disabled',false);
            }
            $("#page_dis").text(dis);
        }


        // 上传图片
        $('#upload_btn').click(function(){
            ST.Util.showBox('上传图片', SITEURL + 'image/insert_view', 0,0, null, null,  parent.document, {loadWindow: window, loadCallback: Insert});
            function Insert(result,bool){
                if(result.data.length>0){
                    var len=result.data.length-1;
                    var temp =result.data[len].split('$$');
                    $('#litimg')[0].src=temp[0];
                    $("#litpic").val(temp[0]);
                }
            }
        });

        //恢复默认
        $("#restore_default").click(function(){
            $("#litpic").val('');
            $("#litimg").attr('src','{$info['default_ico']}');
        });
        //关闭当前窗口
        $(document).on('click','#refuse-btn',function(){
            ST.Util.closeBox();
        });
        // 保存数据
        $(document).on('click','#confirm-btn',function(){
            // 获取保存的数据

            var nav_name  = ($("#nav_name").val()).trim();
            var litimg    = $("#litimg").attr('src');
            var nav_mode  = $("select[name='nav_mode']").val();
            var nav_path  = $("select[name='nav_path']").val();
            var nav_param = $("#nav_param").val();

            if(nav_name === '')
            {
                ST.Util.showMsg('请设置导航名称',5,1000);
                return;
            }
            

            var data = {
                nav_id: "{$info['id']}",
                nav_name: nav_name,
                litimg: litimg,
                nav_mode: nav_mode,
                nav_path: nav_path,
                nav_param: nav_param
            };
            ST.Util.responseDialog(data,true);
        });
    });
</script>
</body>
</html>
